package com.bms.actions;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.bms.utils.DB;
import com.opensymphony.xwork2.ActionSupport;

public class SelectAction  extends ActionSupport{

	private static final long serialVersionUID = 1L;
	private List<String> city;
	private List<String> theatre;
	private List<String> times;
	
	private String yourCity;
	private String yourTheatre;
	private String yourTime;
	private String citySelected;
	private String movieName;
	
	
	
	public String getMovieName() {
		return movieName;
	}
	public void setMovieName(String movieName) {
		this.movieName = movieName;
	}
	
	public List<String> getCity() {
		return city;
	}
	public void setCity(List<String> city) {
		this.city = city;
	}
	public List<String> getTimes() {
		return times;
	}
	public void setTimes(List<String> times) {
		this.times = times;
	}
	public String getYourTime() {
		return yourTime;
	}
	public void setYourTime(String yourTime) {
		this.yourTime = yourTime;
	}
	public String getYourCity() {
		return yourCity;
	}
	
	public List<String> getTheatre() {
		return theatre;
	}
	public void setTheatre(List<String> theatre) {
		this.theatre = theatre;
	}
	public String getYourTheatre() {
		return yourTheatre;
	}
	public void setYourTheatre(String yourTheatre) {
		this.yourTheatre = yourTheatre;
	}
	
	public void setYourCity(String yourCity) {
		this.yourCity = yourCity;		
	}
	
	public String getDefaultCity() {
		System.out.println("default city : " +citySelected);
		return citySelected;
	}
	
	public String getCitySelected() {
		return citySelected;
	}
	public void setCitySelected(String citySelected) {
		this.citySelected = citySelected;
	}
	public SelectAction(){
		System.out.println("in construcotr");
		theatre = new ArrayList<String>();
		Connection con;
		ResultSet result = null;
		String query1;
		city = new ArrayList<String>();
		times = new ArrayList<String>();
		times.add("11:00");
		times.add("2:00");
		times.add("6:00");
		times.add("9:00");
		
		try{
			con =  DB.getConnection();
			query1 = "select * from city";
			result = DB.readFromDB(query1,con);
			while(result.next()){
				String cityName = result.getString("city_name");
				city.add(cityName);
			}
			con.close();
		}
		catch(Exception e){
			System.out.println("Exception : " +e);
		}
	}
	public String display(){
		System.out.println("in display");
		//check
		Connection con;
		ResultSet result = null;
		String query1;
		city = new ArrayList<String>();
		try{
			con =  DB.getConnection();
			query1 = "select * from city";
			result = DB.readFromDB(query1,con);
			while(result.next()){
				String cityName = result.getString("city_name");
				city.add(cityName);
			}
			con.close();
		}
		catch(Exception e){
			System.out.println("Exception : " +e);
		}
		//check	
	
		return NONE;
	}
	public String set(){
		System.out.println("in set method");
		System.out.println("val: "+ citySelected);
		Connection con;
		ResultSet result = null;
		String query2;
		theatre = new ArrayList<String>();
		try{
			con =  DB.getConnection();
			query2 = "select theatre_name,theatre_loc from theatre where city_id = (select city_id from city where city_name ='" + citySelected + "')";
			result = DB.readFromDB(query2,con);
			while(result.next()){
				String th_name = result.getString("theatre_name");
				String th_loc = result.getString("theatre_loc");
				System.out.println("theatre : " +th_name+":"+th_loc);
				theatre.add(th_name+":"+th_loc);	
			}
			con.close();
			//System.out.println("successfully executed");
		}
		catch(Exception e){
			System.out.println("Exception : " +e);
		}
		return SUCCESS;
	}
	public String execute(){
		
		System.out.println("In execute method");
		System.out.println("City selecetd is :" + yourCity);
		System.out.println("Theatre selecetd is :" + yourTheatre);
		System.out.println("Movie Name is :" + movieName);
		System.out.println("Times selecetd is :" + yourTime);
		return SUCCESS;
	}
	

}